package currentment.testIncrease;

public class IncrementTest {
    private static int count = 0; // 普通整数
    private static final int ITERATIONS = 10000; // 每个线程的递增次数
    private static final int THREAD_COUNT = 10; // 线程数量

    public static void main(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[THREAD_COUNT];

        // 启动多个线程进行递增操作
        for (int i = 0; i < THREAD_COUNT; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < ITERATIONS; j++) {
                    count++; // 进行非原子递增操作
                }
            });
            threads[i].start(); // 启动线程
        }

        // 等待所有线程完成
        for (Thread thread : threads) {
            thread.join();
        }

        // 输出最终结果
        System.out.println("Final count: " + count);
    }
}
